"""
Case Type   : 事件触发器
Case Name   : 【事件触发器】创建事件触发器，关联函数不存在，创建失败
Create At   :   2024/07/13
Owner       :   sungang14
Description :
    预置条件：
        1.DROP FUNCTION if exists f_eventtrigger_0039();
    测试步骤：
        1、create EVENT TRIGGER evtri1_eventtrigger_0039 ON ddl_command_start execute procedure f_eventtrigger_0039();
Expect      : 
        1、创建失败，报错函数不存在
History     : 
"""

import sys
import os
import unittest
from yat.test import Node
from yat.test import macro

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH


class IndexFileDamaged(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.logger.info('----------------this is setup-----------------------')
        self.DB_ENV_PATH = macro.DB_ENV_PATH
        self.DB_INSTANCE_PATH = macro.DB_INSTANCE_PATH
        self.comsh = CommonSH('PrimaryDbBmode')
        self.comsh.execut_db_sql("drop EVENT TRIGGER if exists evtri1_eventtrigger_0039;")
        self.comsh.execut_db_sql("drop function if exists  f_eventtrigger_0039();")

    def test_Index_file_damaged(self):
        self.logger.info(
            "创建事件触发器:create EVENT TRIGGER evtri1_eventtrigger_0039 ON ddl_command_start execute procedure f_eventtrigger_0039();")
        msg = self.comsh.execut_db_sql(
            "create EVENT TRIGGER evtri1_eventtrigger_0039 ON ddl_command_start execute procedure f_eventtrigger_0039();")
        self.logger.info(msg)
        self.assertEqual("ERROR:  function f_eventtrigger_0039() does not exist", msg)

    def tearDown(self):
        self.logger.info('----------------this is tearDown-----------------------')
        # 无处理
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
